package com.ty.consumer;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class FanoutConsumer2 {

    //定义一个队列 持久化 Q1
    @Bean
    public Queue Q2(){
        return QueueBuilder.durable("Q2").autoDelete().build();
    }

    //定义一个交换机Direct-ex  持久化 Q1
    @Bean
    public Exchange exchange2(){
        return ExchangeBuilder.fanoutExchange("Fanout-ex").durable( true).build();
    }

    //队列和交换机的绑定关系
    @Bean
    public Binding binding2(){
        return BindingBuilder.bind(Q2()).to(exchange2()).with("").noargs();
    }

    @RabbitListener(queues = "Q2")
    public void consumer2(String msg){
        System.out.println("consumer2接收到消息："+msg);
    }


}
